package io.serializable;

import framework.AbstractTest;
import utils.Log;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

/**
 * Created by shane on 2018/5/28.
 */
public class Blip extends AbstractTest {
    private static final String TAG = "Blip";

    @Override
    public void test(String[] args) {
        super.test(args);

        String outPath = getDefTempFile(args);
        try {
            Log.vn("constructing objects:");
            Blip1 blip1 = new Blip1();
            Blip2 blip2 = new Blip2();

            ObjectOutputStream o = new ObjectOutputStream(new FileOutputStream(outPath));
            Log.vn("saving objects:");
            o.writeObject(blip1);
            o.writeObject(blip2);
            o.close();

            ObjectInputStream in = new ObjectInputStream(new FileInputStream(outPath));
            Log.vn("recovering blip1:");
            blip1 = (Blip1) in.readObject();
            in.close();

            // OOPS! Throws an exception, 抛出异常是因为 Blip2的构造函数不是 public的
            Log.vn("recovering blip2:");
            blip2 = (Blip2) in.readObject();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    protected String getTag() {
        return TAG;
    }
}
